home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / docs / mags / AIOV55.lha / AIOIssue55 / examples / 2.3.0_pointers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-01-01  |  966 b   |  18 lines

  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5.   int i = 0;      /* A normal int. */
  6.   int *pInt = &i; /* An int pointer, initialised to the address of i. pInt is now an "alias" for i. */
  7.   int **ppInt = &pInt; /* This might get confusing. You can ignore it for now if you want; it's a pointer to another pointer. This other pointer is an int pointer, which points to the data i holds :-) */
  8.  
  9.   i = 2; /* Make i equal two. Nothing new here. */
  10.   printf("\n&i == %p. pInt == %p. &pInt == %p. i == %i. *pInt == %i.", &i, pInt, &pInt, i, *pInt);
  11.   *pInt = 5; /* Dereferenced; we'e not changing the pointer itself, but the data the pointer points to */
  12.   printf("\n&i == %p. pInt == %p. &pInt == %p. i == %i. *pInt == %i.", &i, pInt, &pInt, i, *pInt);
  13.   **ppInt = 97696; /* Double dereferenced; we're changing the data at the address of the address held in ppInt */
  14.   printf("\n&i == %p. pInt == %p. &pInt == %p. i == %i. *pInt == %i.", &i, pInt, &pInt, i, *pInt);
  15.  
  16.   return 0;
  17. }
  18.